﻿#include "../HDCCameraControlWidget.h"
#include "../../include/HGlobalVariable.h"
#include "../../include/StdAfx.h"


HDCCameraControlWidget::HDCCameraControlWidget(QWidget *parent)
    :QWidget(parent)
{
    initUI();
}

HDCCameraControlWidget::~HDCCameraControlWidget()
{

}

int HDCCameraControlWidget::currentSliderValue()
{
    return m_psliderSpeed->value();
}

void HDCCameraControlWidget::initUI()
{
    setObjectName("cameraControl_wnd_main");
    m_pvblMain = new QVBoxLayout();
    m_pvblMain->setContentsMargins(0,0,0,0);
    m_pvblMain->addSpacing(25);

    m_phblUp = new QHBoxLayout();
    m_phblUp->setContentsMargins(0,0,0,0);
    m_phblUp->setSpacing(15);

    m_pvblSubControl = new QVBoxLayout();
    m_pvblSubControl->setSpacing(40);
    m_pvblSubControl->setContentsMargins(0,0,0,0);

    m_phblCamera = new QHBoxLayout();
    m_phblCamera->setSpacing(5);
    m_phblCamera->setContentsMargins(0,0,0,0);

    m_phblFocalDistance = new QHBoxLayout();
    m_phblFocalDistance->setSpacing(5);
    m_phblFocalDistance->setContentsMargins(0,0,0,0);

    m_phblAperture = new QHBoxLayout();
    m_phblAperture->setSpacing(5);
    m_phblAperture->setContentsMargins(0,0,0,0);

    m_phblSpeed = new QHBoxLayout();
    m_phblSpeed->setSpacing(10);
    m_phblSpeed->setContentsMargins(0,0,0,0);

    m_pwndCirclePanel = new HUICCirclePanelNoAni(this);

    m_plblCamera = new QLabel();
    m_plblCamera->setObjectName("dc_lbl_sliderSpeed");
    m_plblCamera->setText(QString::fromLocal8Bit("镜头"));

    m_ppbCameraAdd = new QPushButton();
    m_ppbCameraAdd->setFixedSize(g_nCameraControlBtnWidth,g_nCameraControlBtnWidth);
    m_ppbCameraAdd->setObjectName("cameraControl_btn_add");
	m_ppbCameraAdd->setToolTip(QString::fromLocal8Bit("镜头拉近"));

    m_ppbCameraDecrease = new QPushButton();
    m_ppbCameraDecrease->setFixedSize(g_nCameraControlBtnWidth,g_nCameraControlBtnWidth);
    m_ppbCameraDecrease->setObjectName("cameraControl_btn_dec");
	m_ppbCameraDecrease->setToolTip(QString::fromLocal8Bit("镜头拉远"));

    m_plblFocalDistance = new QLabel();
    m_plblFocalDistance->setObjectName("dc_lbl_sliderSpeed");
    m_plblFocalDistance->setText(QString::fromLocal8Bit("焦距"));

    m_ppbFocalDistanceAdd = new QPushButton();
    m_ppbFocalDistanceAdd->setFixedSize(g_nCameraControlBtnWidth,g_nCameraControlBtnWidth);
    m_ppbFocalDistanceAdd->setObjectName("cameraControl_btn_add");
	m_ppbFocalDistanceAdd->setToolTip(QString::fromLocal8Bit("焦距变大"));

    m_ppbFocalDistanceDecrease = new QPushButton();
    m_ppbFocalDistanceDecrease->setFixedSize(g_nCameraControlBtnWidth,g_nCameraControlBtnWidth);
    m_ppbFocalDistanceDecrease->setObjectName("cameraControl_btn_dec");
	m_ppbFocalDistanceDecrease->setToolTip(QString::fromLocal8Bit("焦距变小"));

    m_plblAperture = new QLabel();
    m_plblAperture->setObjectName("dc_lbl_sliderSpeed");
    m_plblAperture->setText(QString::fromLocal8Bit("光圈"));

    m_ppbApertureAdd = new QPushButton();
    m_ppbApertureAdd->setFixedSize(g_nCameraControlBtnWidth,g_nCameraControlBtnWidth);
    m_ppbApertureAdd->setObjectName("cameraControl_btn_add");
	m_ppbApertureAdd->setToolTip(QString::fromLocal8Bit("光圈变大"));

    m_ppbApertureDecrease = new QPushButton();
    m_ppbApertureDecrease->setFixedSize(g_nCameraControlBtnWidth,g_nCameraControlBtnWidth);
    m_ppbApertureDecrease->setObjectName("cameraControl_btn_dec");
	m_ppbApertureDecrease->setToolTip(QString::fromLocal8Bit("光圈变小"));

    m_psliderSpeed = new QSlider();
    m_psliderSpeed->setMinimum(0);
    m_psliderSpeed->setMaximum(50);
    m_psliderSpeed->setSingleStep(1);
    m_psliderSpeed->setOrientation(Qt::Horizontal);
    m_psliderSpeed->setObjectName("dc_slider_speed");
	m_psliderSpeed->setValue(7);

    m_plblSpeed = new QLabel();
    m_plblSpeed->setObjectName("dc_lbl_sliderSpeed");
    QString strTemp;
    m_plblSpeed->setText(strTemp.setNum(m_psliderSpeed->value()));
    m_plblSpeed->setFixedWidth(40);

    m_phblCamera->addWidget(m_plblCamera);
    m_phblCamera->addWidget(m_ppbCameraAdd);
    m_phblCamera->addWidget(m_ppbCameraDecrease);

    m_phblFocalDistance->addWidget(m_plblFocalDistance);
    m_phblFocalDistance->addWidget(m_ppbFocalDistanceAdd);
    m_phblFocalDistance->addWidget(m_ppbFocalDistanceDecrease);

    m_phblAperture->addWidget(m_plblAperture);
    m_phblAperture->addWidget(m_ppbApertureAdd);
    m_phblAperture->addWidget(m_ppbApertureDecrease);

    m_pvblSubControl->addLayout(m_phblCamera);
    m_pvblSubControl->addLayout(m_phblFocalDistance);
    m_pvblSubControl->addLayout(m_phblAperture);

    m_phblUp->addWidget(m_pwndCirclePanel);
    m_phblUp->addLayout(m_pvblSubControl);

    m_phblSpeed->addWidget(m_psliderSpeed,50);
    m_phblSpeed->addWidget(m_plblSpeed,1);

    m_pvblMain->addLayout(m_phblUp);
    m_pvblMain->addLayout(m_phblSpeed);

    this->setLayout(m_pvblMain);

    connect(m_psliderSpeed,SIGNAL(valueChanged(int)),this,SLOT(sltSliderValueChanged(int)));
    connect(m_pwndCirclePanel,SIGNAL(sigClick(ButtonPosition, ButtonType)),this,SLOT(sltCircelPanelBtnClicked(ButtonPosition, ButtonType)));

    connect(m_ppbCameraAdd,SIGNAL(pressed()),this,SLOT(sltCameraAddPressed()));
    connect(m_ppbCameraAdd,SIGNAL(released()),this,SLOT(sltCameraAddReleased()));
    connect(m_ppbCameraDecrease,SIGNAL(pressed()),this,SLOT(sltCameraDecPressed()));
    connect(m_ppbCameraDecrease,SIGNAL(released()),this,SLOT(sltCameraDecPressed()));

    connect(m_ppbFocalDistanceAdd,SIGNAL(pressed()),this,SLOT(sltFocalDistanceAddPressed()));
    connect(m_ppbFocalDistanceAdd,SIGNAL(released()),this,SLOT(sltFocalDistanceAddReleased()));
    connect(m_ppbFocalDistanceDecrease,SIGNAL(pressed()),this,SLOT(sltFocalDistanceDecPressed()));
    connect(m_ppbFocalDistanceDecrease,SIGNAL(released()),this,SLOT(sltFocalDistanceDecReleased()));

    connect(m_ppbApertureAdd,SIGNAL(pressed()),this,SLOT(sltApertureAddPressed()));
    connect(m_ppbApertureAdd,SIGNAL(released()),this,SLOT(sltApertureAddReleased()));
    connect(m_ppbApertureDecrease,SIGNAL(pressed()),this,SLOT(sltApertureDecPressed()));
    connect(m_ppbApertureDecrease,SIGNAL(released()),this,SLOT(sltApertureDecReleased()));
}

void HDCCameraControlWidget::paintEvent(QPaintEvent *event)
{
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    QWidget::paintEvent(event);
}

void HDCCameraControlWidget::sltSliderValueChanged(int nValue)
{
    QString strTemp;
    m_plblSpeed->setText(strTemp.setNum(nValue));
}

void HDCCameraControlWidget::sltCircelPanelBtnClicked(ButtonPosition position, ButtonType type)
{
    int nPosition = (int)position;
    int nType = (int)type;
    emit sigCircelPanelBtnClicked(QVariant(nPosition),QVariant(nType));
}

void HDCCameraControlWidget::sltCameraAddPressed()
{
    emit sigFunctionBtnClicked(QVariant((int)HEDCCF_CAMERA_ADD),QVariant((int)BTN_DOWN));
}

void HDCCameraControlWidget::sltCameraAddReleased()
{
    emit sigFunctionBtnClicked(QVariant((int)HEDCCF_CAMERA_ADD),QVariant((int)BTN_UP));
}

void HDCCameraControlWidget::sltCameraDecPressed()
{
    emit sigFunctionBtnClicked(QVariant((int)HEDCCF_CAMERA_DEC),QVariant((int)BTN_DOWN));
}

void HDCCameraControlWidget::sltCameraDecReleased()
{
    emit sigFunctionBtnClicked(QVariant((int)HEDCCF_CAMERA_DEC),QVariant((int)BTN_UP));
}

void HDCCameraControlWidget::sltFocalDistanceAddPressed()
{
    emit sigFunctionBtnClicked(QVariant((int)HEDCCF_FOCALDISTANCE_ADD),QVariant((int)BTN_DOWN));
}

void HDCCameraControlWidget::sltFocalDistanceAddReleased()
{
    emit sigFunctionBtnClicked(QVariant((int)HEDCCF_FOCALDISTANCE_ADD),QVariant((int)BTN_UP));
}

void HDCCameraControlWidget::sltFocalDistanceDecPressed()
{
    emit sigFunctionBtnClicked(QVariant((int)HEDCCF_FOCALDISTANCE_DEC),QVariant((int)BTN_DOWN));
}

void HDCCameraControlWidget::sltFocalDistanceDecReleased()
{
    emit sigFunctionBtnClicked(QVariant((int)HEDCCF_FOCALDISTANCE_DEC),QVariant((int)BTN_UP));
}

void HDCCameraControlWidget::sltApertureAddPressed()
{
    emit sigFunctionBtnClicked(QVariant((int)HEDCCF_APERTURE_ADD),QVariant((int)BTN_DOWN));
}

void HDCCameraControlWidget::sltApertureAddReleased()
{
    emit sigFunctionBtnClicked(QVariant((int)HEDCCF_APERTURE_ADD),QVariant((int)BTN_UP));
}

void HDCCameraControlWidget::sltApertureDecPressed()
{
    emit sigFunctionBtnClicked(QVariant((int)HEDCCF_APERTURE_DEC),QVariant((int)BTN_DOWN));
}

void HDCCameraControlWidget::sltApertureDecReleased()
{
    emit sigFunctionBtnClicked(QVariant((int)HEDCCF_APERTURE_DEC),QVariant((int)BTN_UP));
}
